/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


var log = false;
var id = 1;
jQuery(document).ready(function(){
         /*  if (!db)
        { // call init method }
        }*/
    
       // $('#profile').hide();
       
    // add radio botton(CIS,BIT) in sign UP page (page2) 
        check_student ();
        get_Abbreviation();
        get_doctor_name();
        get_group_name ();
        
    // year select in sign UP page (page2)
        var myDate = new Date();
        var year = myDate.getFullYear();
        for(var i = 2009; i < year+1; i++)
        {
          $( "#year" ).append('<option value="'+ i +'">'+i+'</option>' );
          $( "#year1" ).append('<option value="'+ i +'">'+i+'</option>' );
          
        }
      
     $("#S_UP").on("click", function(){
             $.mobile.changePage("#page2");
     });
       
       
      $("#b_sub").on("click", function(){
         //  log = true;
           Insert_Student();
           
           //$( "#S_UP" ).buttonMarkup( "disable" );
           $( "[type='submit']" ).button( "disable" );
         //  var pro = '<button id="profile" data-inline="true">Profile</button>';
           // $( "#con" ).append(pro);
        });
        
        
     $("#login").on("click", function(){
         
         
         log = true ;
        get_pass (); 
   
        });
        $("#profile").on("click", function(){
            
             $.mobile.changePage("#page5");
             fill_student_info();
        });
        
        
     $("#B_import").on("click", function(){
        
      $( "#program" ).load( "UJ.htm" , function(){
          var classes = $("#program div table tbody tr td table tbody tr td form table tbody tr td table tbody tr") ;
      var classe = null ;
      var index = 0;
      for( var i = 2 ; i < classes.length ; i++ ){
          classe = classes.get(i);
          var classnum = $($(classe).find('td').get(9)).find("font").text();
           classnum = classnum.trim();
          var sectionnum = $($(classe).find('td').get(8)).find("font").text();
           sectionnum = sectionnum.trim();
          var sectionday= $($(classe).find('td').get(5)).find("font").text();
          sectionday = sectionday.trim();
          var sectiontime= $($(classe).find('td').get(4)).find("font").text();
          sectiontime =  sectiontime.trim();
          var classroom= $($(classe).find('td').get(3)).find("font").text();
          classroom = classroom.trim();
          var doctorname = $($(classe).find('td').get(2)).find("font").text();
          doctorname= doctorname.trim();
          var stutus = $($(classe).find('td').get(1)).find("font").text();
          stutus = stutus.trim();
          index = index +1 ;
          insert_class (index,classnum,sectionnum,sectionday,sectiontime,classroom,doctorname,stutus);
         
        //$('#output').append(classnum + " " + sectionnum +" "+sectionday + " " + "<br/>");
       
      }
    });
     
      
         });
        
        $("#logout").on("click", function(){
            if (log === true)
            {
                 log = false;
                  $("#text_password").val('');
                 $.mobile.changePage("#page1");
                 check_student ();
                
               
             }
            });
             $("#logout2").on("click", function(){
            if (log === true)
            {
                 log = false;
                  $("#text_password").val('');
                 $.mobile.changePage("#page1");
                  check_student ();
                
               
             }

             });
    /*  $("#back_to").on("click", function(){
                 $.mobile.changePage("#page1");
               //  check_display_profile();
        });
        */
      $("#_back").on("click", function(){
                  $.mobile.changePage("#page1");
                    $("#text_password").val('');
                   //check_display_profile();
          });
          
     $("#update").on("click", function(){
             $.mobile.changePage("#page3");
        });
        
        $("#B_Save").on("click", function(){
           var checkcourse=  $('.change')  ;
           var _course =null;
           var val ;
            for( var i = 0 ; i < checkcourse.length ; i++ )
            {
                _course= checkcourse.get(i);
                val = $(_course).val();
                if ($(_course).is(':checked'))
                {
                     insert_course_taken(id,val );
                     id = id +1;
                }
                else
                {
                    delete_course_taken(val);
                }
            }
              });
    
    $("#p_save").on("click", function(){
        change_info();
    });
    $("#reset").on("click", function(){
        delete_student ();
        delete_classes();
        delete_coursetaken();
        $( "[type='submit']" ).button( "enable" );
         $.mobile.changePage("#page1");
         $("#text_password").val('');
        
    });
     $("#guide").on("click", function(){
          $.mobile.changePage("#page4");
          compare();
    });
    
     $("#save_sch").on("click", function(){
         
          insert_to_sch();
    });
    
    $("#Day_List").change( function (){
      var value =  $(this).val();
      // alert(value);
      if (value === "not-matter")
      {
          $( "#available .course" ).removeClass('hidebyday');
      }else
      {
      $( "#available .course" ).removeClass('hidebyday');  
      $( "#available .course" ).not("."+value).addClass('hidebyday');
     // $( ".course ."+value ).addClass('hide');
      }   
    });
    $("#Time_List").change( function (){
          
       var value =  $(this).val();
      // alert(value);
      if (value === "not-matter")
      {
          $( "#available .course" ).removeClass('hidebytime');
      }else
      {
      $( "#available .course" ).removeClass('hidebytime');  
      $( "#available .course" ).not("."+value).addClass('hidebytime');
      }
      });
      
       $("#doctor_List").change( function (){
          
       var value =  $(this).val();
       if (value === "not-matter")
      {
          $( "#available .course" ).removeClass('hidebydoctor');
      }else
      {
      $( "#available .course" ).removeClass('hidebydoctor');  
      $( "#available .course" ).not("."+value).addClass('hidebydoctor');
      }
      });
      
        
      $ ("#level").change ( function (){
          var value = $(this).val();
           if (value === "not-matter")
      {
          $( "#available .course" ).removeClass('hide');
      }else
      {
         $( "#available .course" ).removeClass('hide');
         $( "#available .course" ).not("."+value).addClass('hide');
     }
      });   
         
      $ ("#group").change ( function (){
          var value = $(this).val();
           if (value === "not-matter")
          {
          $( "#available .course" ).removeClass('hidebygroup');
          }else
          {
             $( "#available .course" ).removeClass('hidebygroup');
             $( "#available .course" ).not("."+value).addClass('hidebygroup');
          }
      });     
       
});
